<%@ page import="weaver.general.Util" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet"/>
<jsp:useBean id="rs2" class="weaver.conn.RecordSet"/>
<%
    String json = "{\"flag\":\"0\"}";
    String mbjson = "";
    String maintable = "";
    String dt1table = "";
    String dt2table = "";
    String mzwxid = Util.null2String(request.getParameter("mzwxid"));
    String wxworkflowid = Util.null2String(request.getParameter("wxworkflowid"));
    if ("105".equals(wxworkflowid)) {//维修封测
        maintable = "formtable_main_179";
        dt1table = "formtable_main_179_dt1";
        dt2table = "formtable_main_179_dt2";
    } else if ("104".equals(wxworkflowid)) {//模组维修
        maintable = "formtable_main_175";
        dt1table = "formtable_main_175_dt1";
        dt2table = "formtable_main_175_dt2";
    }
    rs.executeQuery("select id,xz,gysbm,gys,dz,wxrdh,email,lcbh,xm,bm,rq,sj,gh,ks,dh from " + maintable + " where requestid='" + mzwxid + "'");
    rs.next();
    String mainid = Util.null2String(rs.getString("id"));
    String xz = Util.null2String(rs.getString("xz"));
    String gysbm = Util.null2String(rs.getString("gysbm"));
    String gys = Util.null2String(rs.getString("gys"));
    String dz = Util.null2String(rs.getString("dz"));
    String wxrdh = Util.null2String(rs.getString("wxrdh"));
    String email = Util.null2String(rs.getString("email"));
    String lcbh = Util.null2String(rs.getString("lcbh"));
    String xm = Util.null2String(rs.getString("xm"));
    String bm = Util.null2String(rs.getString("bm"));
    String rq = Util.null2String(rs.getString("rq"));
    String sj = Util.null2String(rs.getString("sj"));
    String gh = Util.null2String(rs.getString("gh"));
    String ks = Util.null2String(rs.getString("ks"));
    String dh = Util.null2String(rs.getString("dh"));
    //明细表1
    rs1.executeQuery("select sapcode,commodity,description,pn,quantity1,us,Suttle,cname,Photo from " + dt1table + " where mainid='" + mainid + "'");
    bb.writeLog("select sapcode,commodity,description,pn,quantity1,us,Suttle,cname,Photo from " + dt1table + " where mainid='" + mainid + "'");
    while (rs1.next()) {
        String str = "";
        String sapcode = Util.null2String(rs1.getString("sapcode"));
        String commodity = Util.null2String(rs1.getString("commodity"));
        String description = Util.null2String(rs1.getString("description"));
        String pn = Util.null2String(rs1.getString("pn"));
        String quantity1 = Util.null2String(rs1.getString("quantity1"));
        String us = Util.null2String(rs1.getString("us"));
        String Suttle = Util.null2String(rs1.getString("Suttle"));
        String zwpm = Util.null2String(rs1.getString("cname"));
        String tp = Util.null2String(rs1.getString("Photo"));

        //明细表2
        rs2.executeQuery("select prno from " + dt2table + " where mainid='" + mainid + "'");
        bb.writeLog("select prno from " + dt2table + " where mainid='" + mainid + "'");
        while (rs2.next()) {
            String prno = Util.null2String(rs2.getString("prno"));
            String str1 = "{\"prno\":\"" + prno + "\",\"sapcode\":\"" + sapcode + "\",\"commodity\":\"" + commodity + "\",\"description\":\"" + description
                    + "\",\"pn\":\"" + pn + "\",\"us\":\"" + us + "\",\"Suttle\":\"" + Suttle + "\",\"quantity1\":\"" + quantity1
                    + "\",\"zwpm\":\"" + zwpm + "\",\"tp\":\"" + tp + "\"}";
            if ("".equals(str)) {
                str = str1;
            } else {
                str += "," + str1;
            }
        }
        if ("".equals(str)) {
            str = "{\"sapcode\":\"" + sapcode + "\",\"commodity\":\"" + commodity + "\",\"description\":\"" + description
                    + "\",\"pn\":\"" + pn + "\",\"us\":\"" + us + "\",\"Suttle\":\"" + Suttle + "\",\"quantity1\":\"" + quantity1
                    + "\",\"zwpm\":\"" + zwpm + "\",\"tp\":\"" + tp + "\"}";
        }

        if ("".equals(mbjson)) {
            mbjson = str;
        } else {
            mbjson += "," + str;
        }

    }


    if (!"".equals(mbjson)) {
        json = "{\"flag\":\"1\",\"mb\":[" + mbjson + "],\"xz\":\"" + xz + "\",\"gysbm\":\"" + gysbm + "\",\"gys\":\"" + gys
                + "\",\"dz\":\"" + dz + "\",\"wxrdh\":\"" + wxrdh + "\",\"email\":\"" + email + "\",\"lcbh\":\"" + lcbh
                + "\",\"xm\":\"" + xm + "\",\"bm\":\"" + bm + "\",\"rq\":\"" + rq + "\",\"sj\":\"" + sj
                + "\",\"gh\":\"" + gh + "\",\"ks\":\"" + ks + "\",\"dh\":\"" + dh + "\",\"mzwxid\":\"" + mzwxid + "\"}";
    }

    out.print(json);
    bb.writeLog("json", json);
%>

